package com.novoda.runbuddy.view.overlay;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.location.Location;

import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
//import com.google.googlenav.DrivingDirection;
import com.novoda.runbuddy.R;
import com.novoda.runbuddy.activity.CurrentRunMap;

public class DetailsOverlay extends Overlay {

	CurrentRunMap				mapOfJogActivity	= null;
	//DrivingDirection			drivingDirections	= null;

	@SuppressWarnings("unused")
	private Bitmap				PIN_START			= null;
	private Bitmap				INFO_LOWER_LEFT		= null;
	protected List<Location>	path				= new ArrayList<Location>();
	int[]						screenCoords		= { 0, 0 };
	boolean						firstInPath;
	boolean						first				= true;
	private String				time				= "00:00:00.00";
	private Calendar			calendar;
	private String				dateString;

	public DetailsOverlay(CurrentRunMap map, Bitmap infoImageBG) {
		mapOfJogActivity = map;
		INFO_LOWER_LEFT = infoImageBG;

		calendar = new GregorianCalendar();
		this.dateString = new String(Integer.toString(calendar.get(Calendar.DAY_OF_MONTH)) + '/'
				+ Integer.toString(calendar.get(Calendar.MONTH)) + '/' + Integer.toString(calendar.get(Calendar.YEAR)));
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		super.draw(canvas, mapView, shadow);
		if (!shadow) {
			drawDetailsIndicator(canvas);
		}
	}

	private void drawDetailsIndicator(Canvas canvas) {
		int totalHeightOfView = this.mapOfJogActivity.findViewById(R.id.map).getHeight();

		int heightOfInfoDialBGImage = 75;
		canvas.drawBitmap(this.INFO_LOWER_LEFT, 0, totalHeightOfView - heightOfInfoDialBGImage, getRoutePathPainter());

		canvas.drawText(this.time, 5, totalHeightOfView - 5, getJourneyTimePainter());
		canvas.drawText(this.dateString, 4, totalHeightOfView - 35, getJourneyDistPainter());

	}

	protected Paint getJourneyTimePainter() {
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setARGB(255, 255, 255, 255);
		paint.setStrokeWidth(1);
		paint.setStyle(Paint.Style.FILL_AND_STROKE);
		paint.setTextSize(24);
		return paint;
	}

	protected Paint getJourneyDistPainter() {
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setARGB(255, 255, 255, 255);
		paint.setStrokeWidth(1);
		paint.setStyle(Paint.Style.FILL_AND_STROKE);
		paint.setTextSize(16);
		return paint;
	}

	protected Paint getRoutePathPainter() {
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setStrokeWidth(4);
		paint.setARGB(175, 113, 105, 252);
		paint.setStyle(Paint.Style.STROKE);
		return paint;
	}

	public void addLocationToPath(Location pointLocation) {
		path.add(pointLocation);
	}

	public void setTime(String time) {
		this.time = time;
	}
}
